package com.example.houseman.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.houseman.entity.TbRoomInfo;
import com.example.houseman.enums.PaymentMortgage;
import com.example.houseman.enums.PaymentPay;
import com.example.houseman.service.ITbRoomInfoService;
import com.org.dto.RoomInfoDto;
import com.org.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 龚梦
 * @since 2021-03-31
 */
@RestController
@RequestMapping("/hou/TbRoomInfoController")
public class TbRoomInfoController {

    @Autowired
    private ITbRoomInfoService roomInfoService;

    @RequestMapping("list")
    public ResultEntity list(@RequestBody RoomInfoDto roomInfo) {

        QueryWrapper<TbRoomInfo> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(roomInfo.getStatus())) {
            wrapper.eq("r.status", roomInfo.getStatus());
        }
        if (!StringUtils.isEmpty(roomInfo.getPublishStatus())) {
            wrapper.eq("publish_status", roomInfo.getPublishStatus());
        }
        if (!StringUtils.isEmpty(roomInfo.getName())) {
            wrapper.like("pp.name", roomInfo.getName());
        }
        if (!StringUtils.isEmpty(roomInfo.getRoomName())) {
            wrapper.like("room_name", roomInfo.getRoomName());
        }

        wrapper.orderByDesc("r.recommended");

        Page<TbRoomInfo> page = new Page<>();

        page.setCurrent(roomInfo.getPageNum());

        page.setSize(roomInfo.getPageSize());

        Page<TbRoomInfo> page1 = roomInfoService.getList(wrapper, page);

        return ResultEntity.ok("200", "查询成功", page1);
    }

    @RequestMapping("recommend")
    public ResultEntity recommend(@RequestBody TbRoomInfo roomInfo) {

        roomInfo.setRecommended(2);

        boolean b = roomInfoService.updateById(roomInfo);

        return ResultEntity.ok("200", "操作成功", b);
    }

    @RequestMapping("nrecommend")
    public ResultEntity nrecommend(@RequestBody TbRoomInfo roomInfo) {

        roomInfo.setRecommended(1);

        boolean b = roomInfoService.updateById(roomInfo);

        return ResultEntity.ok("200", "操作成功", b);
    }

    /**
     * 查询付款方式-押
     *
     * @return
     */
    @RequestMapping("/getPaymentMortgageList")
    public ResultEntity getPaymentMortgageList() {
        PaymentMortgage[] values = PaymentMortgage.values();
        return ResultEntity.ok("200", "付款方式押", values);
    }

    /**
     * 查询付款方式-付
     *
     * @return
     */
    @RequestMapping("/getPaymentPayList")
    public ResultEntity getPaymentPayList() {
        PaymentPay[] values = PaymentPay.values();
        return ResultEntity.ok("200", "付款方式付", values);
    }
}
